<template>
	<div class="changeClassContainer" v-if="studentdetailprop">
		<el-dialog
			:visible.sync="isShow"
			:close-on-click-modal="modalclose"
			custom-class="el-dialog-bg"
			:before-close="handleClose" >
			<div slot="title" class="panel_title">
				<span>学员转班</span>
			</div>
			<div class="classInfo">
			<div class="StudentInfo" v-if="step==1||step>=2">
				<div class="info">
				<span class="spanlabel">姓名：</span>
				<span class="spanlabelweight">{{studentdetailprop.realName}}</span>
				</div>
				<div class="info">
				<span class="spanlabel">联系人：</span>
				<span class="spanlabelweight">{{studentdetailprop.parentName}}</span>
				</div>
				<div class="info">
				<span class="spanlabel">联系电话：</span>
				<span class="spanlabelweight">{{studentdetailprop.phone}}</span>
				</div>
			</div>

			<div class="OldInfo" v-if="step==1||step>=2">
				<span class="spanlabelassist">原班信息</span>
				<div class="tablecss">
				<table style="width:100%;" cellpadding="0" cellspacing="0">
					<thead>
					<tr>
						<th>班级名称</th>
						<th>类型</th>
						<th>课程总价</th>
						<th>实际支付</th>
						<th>总课时</th>
						<th>已上课时</th>
						<th>课耗</th>
						<th>剩余课时</th>
						<th>剩余课程费用</th>
						<th>班级状态</th>
					</tr>
					</thead>
					<tbody v-if="oldclass">
					<tr>
						<!-- 班级名称 -->
						<td align="center">{{oldclass.className}}</td>
						<!-- 类型 -->
						<td align="center">{{oldclass.courseTypeUnit}}</td>
						<!-- 课程价格 -->
						<td align="center">{{oldclass.coursePackage.totalMoney}}</td>
						<!-- 实际支付 -->
						<td align="center">{{oldclass.realMoney}}</td>
						<!-- 总课时/天 -->
						<td align="center">{{oldclass.courseHour}}</td>
						<!-- 已上课时/天 -->
						<td align="center">{{oldclass.courseUseHour}}</td>
						<!-- 课耗 -->
						<td align="center">
							<!-- {{(oldclass.courseUseHour*(oldclass.realMoney/((oldclass.courseHour+oldclass.courseUseHour)||1))).toFixed(2)}} -->
							{{courseUseMoney}}
						</td>
						<!-- 剩余课时/天 -->
						<td align="center">{{oldclass.courseHour-oldclass.courseUseHour}}</td>
						<!-- 剩余课程费用 -->
						<td align="center">{{surplusCourseMoney}}</td>
						<!-- 班级状态 -->
						<td align="center">{{oldclass.classStatusModeName}}</td>
					</tr>
					</tbody>
					<tbody v-else>
					<tr>
						<td colspan="11" align="center">暂无数据</td>
					</tr>
					</tbody>
				</table>
				</div>
			</div>

			<div class="SelectClassInfo" v-if="step==1">
				<span style="color: red;">*</span>
				<span class="spanlabelassist">请选择转班班级</span>
				<br />
				<span>&nbsp;</span>
				<el-select
					v-model="classtext"
					filterable
					@change="selectClass"
					style="width:3rem;margin-top:0.1rem;"
					placeholder="请输入班级名称"
					>
					<el-option
						v-for="item in classList"
						:key="item.classId"
						:label="item.className"
						:value="item.classId"
					></el-option>
				</el-select>
				<el-collapse-transition>
					<div class="tablecss" v-if="classtext">
						<table style="width:100%;" cellpadding="0" cellspacing="0">
						<thead>
							<tr>
							<th>班级名称</th>
							<th>类型</th>
							<th>上课时间</th>
							<th>教师</th>
							<th>收费模式</th>
							<th>总课时</th>
							<th>课程总价</th>
							<th>班级状态</th>
							<th>班级进度</th>
							</tr>
						</thead>
						<tbody v-if="newclass">
							<tr>
								<td align="center">{{newclass.className}}</td>
								<td align="center">{{newclass.courseTypeUnit}}</td>
								<td align="center">
									{{newclass.startTime}}
									<br>至<br> 
									{{newclass.endTime}}
								</td>
								<td align="center">{{newclass.teacherUserName}}</td>
								<td align="center">{{newclass.chargeModeName}}</td>
								<td align="center">{{newclass.totalCourseHour}}</td>
								<td align="center">{{newclass.coursePackage_totalMoney}}</td>
								<td align="center">{{newclass.classStatusModeName}}</td>
								<td align="center">{{newclass.useCourseHour}}/{{newclass.totalCourseHour}}</td>
							</tr>
						</tbody>
						<tbody v-else>
							<tr>
								<td colspan="11" align="center">暂无数据</td>
							</tr>
						</tbody>
						</table>
					</div>
				</el-collapse-transition>
			</div>

			<div class="NewClassInfo" v-if="step>=2">
				<span class="spanlabelassist">新班信息</span>
				<div class="tablecss">
				<table style="width:100%;" cellpadding="0" cellspacing="0">
					<thead>
					<tr>
						<th>班级名称</th>
						<th>类型</th>
						<th>上课时间</th>
						<th>教师</th>
						<th>班级进度</th>
						<th>课程单价</th>
						<th>课程总价</th>
						<th>购买数量</th>
						<th>合计</th>
					</tr>
					</thead>
					<tbody v-if="newclass">
						<tr>
							<td align="center">{{newclass.className}}</td>
							<td align="center">{{newclass.courseTypeUnit}}</td>
							<td align="center">
								{{newclass.startTime}} 
								<br>至<br>
								{{newclass.endTime}}
							</td>
							<td align="center">{{newclass.teacherUserName}}</td>
							<td align="center">{{newclass.useCourseHour}}/{{newclass.totalCourseHour}}</td>
							<td align="center">{{newclass.courseUnitPrice}}</td>
							<td align="center">{{newclass.coursePackage_totalMoney}}</td>
							<td align="center">
								<el-input-number :disabled="newclass.qrb" size="mini" v-model="buyClassTime" :precision="0"
								:min="1" :max="buyMaxCourseHour" @change="alterBuyNumber"
								label="数量"></el-input-number>
							</td>
							<td align="center">{{getNewClassMaxMoney}}</td>
						</tr>
					</tbody>
					<tbody v-else>
					<tr>
						<td colspan="11" align="center">暂无数据</td>
					</tr>
					</tbody>
				</table>
				</div>
			</div>
			<!-- 收款信息 -->
			<div class="PayInfo" v-if="step>=2&&!payInfo.isRefund">
				<div class="row" style="padding-left:0.2rem;">转班需要补齐班级课程差价，或是退还多余部分：</div>
				<div class="row" style="padding-left:0.2rem;">（课程差价 = 新班总费用 - 原班剩余课程费用）</div>
				<div class="row">
					<span class="spanlabel" >应收金额：</span>
					<span class="spanlabelweight" style="font-size:0.22rem;">￥{{payInfo.recMoney}}</span>
				</div>
				<div class="row" style="padding-left:0.2rem;" v-show="payInfo.orderMoney>0">
					<el-checkbox v-model="checked">
						<span style="font-size:0.16rem;">订金抵扣：￥{{payInfo.orderMoney}}</span>
					</el-checkbox>
				</div>
				<div class="row">
					<span class="spanlabel" necessary="true">实际支付：</span>
					<!-- <el-input style="width:2rem;" type="number" v-model="payInfo.realMoney" placeholder="请输入内容"></el-input> -->
					 <el-input-number v-model="payInfo.realMoney" :precision="2"
					  :step="1" :min="0" :max="payInfo.recMoney" :controls="false"></el-input-number>
				</div>
				<div class="row">
					<span class="spanlabel" necessary="true">支付方式：</span>
				</div>
				<div class="row" style="padding-left:0.2rem;">
					<el-radio
						v-for="item in account_pay_mode"
						:key="item.value"
						v-model="payInfo.payMode"
						:label="item.value"
					>
						<span style="font-size:0.16rem;">{{item.name}}</span>
					</el-radio>
				</div>
				<div class="row">
					<span class="spanlabel">关联业务：</span>
				</div>
				<div class="row">
					<span class="spanlabel" :necessary="!payInfo.needOrderNo">合同号：</span>
					<el-input
						style="width:2rem;"
						v-model="payInfo.orderNo"
						placeholder="请输入内容"
						:disabled="payInfo.needOrderNo"
					></el-input>
					<el-checkbox v-model="payInfo.needOrderNo">无合同</el-checkbox>
				</div>
				<div class="row">
					<span class="spanlabel">备注：</span>
					<el-input style="width:4rem;" placeholder="请输入内容" v-model="payInfo.remark"></el-input>
				</div>
			</div>
			<!-- 退款信息 -->
			<div class="PayInfo" v-else-if="step>=2&&payInfo.isRefund">
				<div class="row" style="padding-left:0.2rem;">转班需要补齐班级课程差价，或是退还多余部分：</div>
				<div class="row" style="padding-left:0.2rem;">（课程差价 = 新班总费用 - 原班剩余课程费用）</div>
				<div class="row">
					<span class="spanlabel" >应退金额：</span>
					<span class="spanlabelweight" style="font-size:0.22rem;">￥{{Math.abs(payInfo.recMoney)}}</span>
				</div>
				<div class="row">
					<span class="spanlabel" necessary="true">实际退费：</span>
					<!-- <el-input style="width:2rem;" v-model="payInfo.realRefundMoney" placeholder="请输入内容"></el-input> -->
					 <el-input-number v-model="payInfo.realRefundMoney" :precision="2"
					  :step="1" :min="0" :max="Math.abs(payInfo.recMoney)" :controls="false"></el-input-number>
				</div>
				<div class="row">
					<span class="spanlabel" necessary="true">退费原因：</span>
					<span class="spanlabelweight">{{payInfo.refundReason}}</span>
				</div>
				<div class="row">
					<span class="spanlabel" necessary="true">退费方式：</span>
				</div>
				<div class="row" style="padding-left:0.2rem;">
					<el-radio disabled v-model="payInfo.payMode" :label="100">
						<span style="font-size:0.16rem;">原路返回</span>
					</el-radio>
					<el-radio :disabled="payInfo.payMode==100" v-model="payInfo.payMode" :label="2">
						<span style="font-size:0.16rem;">现金</span>
					</el-radio>
					<el-radio :disabled="payInfo.payMode==100" v-model="payInfo.payMode" :label="1">
						<span style="font-size:0.16rem;">银行转账</span>
					</el-radio>
					<el-radio :disabled="payInfo.payMode==100" v-model="payInfo.payMode" :label="5">
						<span style="font-size:0.16rem;">POS机</span>
					</el-radio>
				</div>
				<div class="row">
					<span class="spanlabel" necessary="true" style="white-space: nowrap;">收款人信息：</span>
				</div>
				<div class="row">
					<el-input style="width:2rem;" placeholder="收款人姓名" v-model="payInfo.payeeName"></el-input>
					<el-input style="width:2rem;" placeholder="收款人电话" v-model="payInfo.payeePhone"></el-input>
				</div>
			</div>

			</div>
			<!-- 支付/退费 按钮 -->
			<div slot="footer" class="footer-btn" >
				<el-button @click="btnCancel" class="resetElement">
					<span>上一步</span>
				</el-button>
				<el-button v-if="!payInfo.isRefund" type="primary" :disabled="allow" class="resetElement" @click="btnOk"
				>{{step>=2?'确定支付':'下一步'}}
				</el-button>
				<el-button v-else type="primary" :disabled="allow" class="resetElement" @click="btnOk"
				>{{step>=2?'确定退款':'下一步'}}
				</el-button>
			</div>

		</el-dialog>
		<!--成功转班-->
		<el-dialog
			:visible.sync="successdig"
			:close-on-click-modal="modalclose"
			custom-class="el-dialog-bg"
			:before-close="handleClose2" >
			<div slot="title" class="panel_title2">
				<span>成功转班</span>
			</div>
			<div class="successDetail">
				<!-- 支付 -->
				<div class="newclassinfo"  v-if="!payInfo.isRefund">
					<div class="classlistinfo">
						<div class="tablecss">
							<table style="width:100%;" cellpadding="0" cellspacing="0">
								<thead>
									<tr>
										<!-- <th>授课模式</th> -->
										<th>班级</th>
										<!-- <th style="width:1.5rem;">课程</th> -->
										<th>单价</th>
										<th>单位</th>
										<th>购买数量</th>
										<th>合计</th>
										<th>原班剩余费用</th>
										<th>转班支付</th>
										<!-- <th>优惠金额</th>
										<th>优惠名称</th> -->
										<th>订金扣减</th>
										<th>应支付</th>
										<th>状态</th>
									</tr>
								</thead>
								<tbody v-if="newclass">
									<tr>
										<td align="center">{{newclass.className}}</td>
										<td align="center">{{newclass.courseUnitPrice?('￥'+newclass.courseUnitPrice):''}}</td>
										<td align="center">{{newclass.courseTypeUnit}}</td>
										<td align="center">{{buyClassTime}}</td>
										<td align="center">￥{{(buyClassTime*newclass.courseUnitPriceNumber).toFixed(2)}}</td>
										<td align="center">￥{{surplusCourseMoney}}</td>
										<td align="center">￥{{courseTotalMoney}}</td>
										<!-- <td align="center">--</td>
										<td align="center">--</td> -->
										<td align="center">￥{{checked?payInfo.orderMoney:0}}</td>
										<td align="center">￥{{payInfo.recMoney}}</td>
										<td align="center">{{successdig_payState}}</td>
									</tr>
								</tbody>
								<tbody v-else>
									<tr>
									<td colspan="11" align="center">暂无数据</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
					<div class="proceeds">
						<ul>
							<li>
								<span class="spanlabel">总计：</span>
								<span class="spanlabelweight">￥{{payInfo.recMoney}}</span>
							</li>
							<li v-show="payInfo.orderMoney>0">
								<span>订金抵扣：</span>
								<span>￥{{payInfo.orderMoney}}</span>
							</li>
							<li>
								<span class="spantitle">实际支付：</span>
								<span style="color:red;" class="spanlabelimp">￥{{payInfo.realMoney}}</span>
							</li>
						</ul>
					</div>
					<div class="otherinfo">
						<span style="color:#999999;">其他信息：</span>
						<table style="width: 100%;">
							<tr>
								<td>
									<span class="spanlabel">缴费方式：</span>
									<span class="spanlabelweight" >{{payInfo.payModeName}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">跟单人：</span>
									<span class="spanlabelweight">{{otherInfo.executeUserName}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">收款人：</span>
									<span class="spanlabelweight">{{_userInfo.nickName}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">备注：</span>
									<span class="spanlabelweight">{{otherInfo.suceessRemark}}</span>
								</td>
							</tr>
						</table>
					</div>
				</div>
				<!-- 退费 -->
				<div class="newclassinfo"  v-else>
					<div class="classlistinfo">
						<div class="tablecss">
							<table style="width:100%;" cellpadding="0" cellspacing="0">
								<thead>
									<tr>
										<th>班级</th>
										<th>单价</th>
										<th>单位</th>
										<th>购买数量</th>
										<th>合计</th>
										<th>原班剩余费用</th>
										<th>转班退费</th>
										<!-- <th>优惠金额</th>
										<th>优惠名称</th>
										<th>订金扣减</th> -->
										<th>应退费</th>
										<th>状态</th>
									</tr>
								</thead>
								<tbody v-if="newclass">
									<tr>
										<td align="center">{{newclass.className}}</td>
										<td align="center">￥{{newclass.courseUnitPrice}}</td>
										<td align="center">{{newclass.courseTypeUnit}}</td>
										<td align="center">{{buyClassTime}}</td>
										<td align="center">￥{{buyClassTime*newclass.courseUnitPriceNumber}}</td>
										<td align="center">￥{{surplusCourseMoney}}</td>
										<td align="center">￥{{Math.abs(payInfo.recMoney)}}</td>
										<!-- <td align="center">--</td>
										<td align="center">--</td>
										<td align="center">--</td> -->
										<td align="center">￥{{Math.abs(payInfo.recMoney)}}</td>
										<td align="center">{{successdig_payState}}</td>
									</tr>
								</tbody>
								<tbody v-else>
									<tr>
										<td colspan="11" align="center">暂无数据</td>
									</tr>
								</tbody>
							</table>
						</div>
					</div>
					<div class="proceeds">
						<ul>
							<li>
								<span class="spanlabel">总计：</span>
								<span class="spanlabelweight">￥{{Math.abs(payInfo.recMoney)}}</span>
							</li>
							<li>
								<span class="spantitle">实际退费：</span>
								<span style="color:red;" class="spanlabelimp">￥{{(payInfo.realRefundMoney)}}</span>
							</li>
							<!-- <li>
								<span>订金抵扣：</span>
								<span>￥{{Math.abs(payInfo.orderMoney)}}</span>
							</li> -->
						</ul>
					</div>
					<div class="otherinfo">
						<span style="color:#999999;">其他信息：</span>
						<table style="width: 100%;">
							<tr>
								<td>
									<span class="spanlabel">退费订单号：</span>
									<span class="spanlabelweight">{{otherInfo.orderNo}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">第三方订单号：</span>
									<span class="spanlabelweight">{{otherInfo.onlineOrderNo}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">状态：</span>
									<span class="spanlabelweight">{{successdig_payState}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">跟单人：</span>
									<span class="spanlabelweight">{{otherInfo.executeUserName}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">退费操作：</span>
									<span class="spanlabelweight">{{_userInfo.nickName}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">退费方式：</span>
									<span class="spanlabelweight" >{{matchRefundModeName[successdig_payModeName]}}</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="spanlabel">退费原因：</span>
									<span class="spanlabelweight">转班退费</span>
								</td>
							</tr>
						</table>
					</div>
				</div>
				<div class="newclassBtn" @click="showNewClass">
					<div class="line"></div>
					<span>
						新班详情&nbsp;
						<i class="el-icon-arrow-up" v-if="!newclassShow"></i>
						<i class="el-icon-arrow-down" v-else></i>
					</span>
				</div>
				<div class="classdetailInfo" v-if="newclassShow&&classInfo">
					<classComponent :classInfo="classInfo" :studenttuitionmode="studenttuitionmode"></classComponent>
				</div>
			</div>
		</el-dialog>
		<payQRCode ref="payQRCode" @callback="suceessPay" @cancel="cancelPay"></payQRCode>
	</div>
</template>

<script>
import { mapState, mapGetters, mapActions } from "vuex"; //先要引入
import classComponent from "./classComponent";
import payQRCode from "@/components/common/payQRCode";
import fNumber from "@/js/utils/floatnumber.js"
let vm;
export default {
  props: ["studentdetailprop"],
  components: {
    classComponent,payQRCode
  },
  data() {
    return {
	  studenttuitionmode: tool.getDictNameByValue(-100,'student_tuition_mode',false),
	  classInfo:{},
	  _userInfo:{},
      modalclose: false,
      checked: false,
      radio: "1",
      step: 1,
      courseTotalMoney: 0,
      payInfo: {
        recMoney: 0, //应收金额
        orderMoney: 0, //订金抵扣
		realMoney: 0, //实际支付
		realRefundMoney:0,//实际退费
		payMode: null, //缴费方式
		payModeName: null, //缴费方式
        changeClassDate: "",
        remark: "",
        orderNo: "",
		needOrderNo: false,
		//是否为退费
		isRefund:false,
		payeeName:'',
		payeePhone:'',
		refundReason:'转班退费',
      },
      allow: true,
      newclassShow: false,
      successdig: false,
      subscription: false,
      classtext: "",
      newclass: null,
      buyClassTime: 0,
      // changeclassInfo:[{label:'天才班',value:'1'},{label:'庸才班',value:'2'},{label:'蠢才班',value:'3'}],
	  account_pay_mode: [],
	  otherInfo:{
		  orderNo:'',
		  onlineOrderNo:'',
		  statu:'',
		  executeUserName:'',
		  createUserName:'',
		  refundModeName:'',
		  suceessRemark:'',
	  },
	  matchRefundModeName:{
		  1:'银行转账',
		  2:'现金',
		  5:'POS机',
		  100:'原路返回'
	  },
	  successdig_payState:'',
	  successdig_payModeName:'',
	  
    };
  },
  methods: {
    initDialog() {
      this.classtext = "";
      this.step = 1;
      this.allow = true;
      this.payInfo.changeClassDate = "";
      this.newclassShow = false;
      //重置支付信息
      this.payInfo.needOrderNo = false;
      this.payInfo.payMode = null;
      this.payInfo.remark = "";
	  this.payInfo.orderNo = "";
	//   this.payInfo.isRefund=false;
    },
    /**
     * step为0时则为取消，否则为上一步
     */
    btnCancel() {
	  this.step--;
		//   debugger
      //this.payInfo.realMoney = this.payInfo.recMoney - this.payInfo.orderMoney;
      if (this.step == 0) {
        this.initDialog();
		this.$store.dispatch("changeClass/hidechangeClassPanel");
		this.$emit('backselect');
      }
      //重置支付信息
      this.payInfo.needOrderNo = false;
      this.payInfo.payMode = null;
      this.payInfo.remark = "";
	  this.payInfo.orderNo = "";
	  
    },
    /**
     * step为5时否则为下一步
     */
    btnOk() {
		this.step++;if(this.step>3)this.step=3;
		// debugger
		if (this.step == 2) {
			this.payInfo.realMoney = fNumber.subtract(this.payInfo.recMoney , this.payInfo.orderMoney);
			this.payInfo.realRefundMoney = Math.abs(fNumber.subtract(this.payInfo.recMoney , this.payInfo.orderMoney));
		}
		
		if (this.step == 3) {
			this.step=2;
			// 校验
			let payMsg='';
			if(this.payInfo.isRefund){
				payMsg='请选择退费方式';
				if(!this.payInfo.payeeName){
					this.$message({
						type:'warning',
						message:'请输入收款人姓名！'
					});
					return;
				}
				if(!tool.judge('name',this.payInfo.payeeName)){
					this.$message({
						type:'warning',
						message:'请输入正确的姓名！'
					});
					return;
				}
				if(!this.payInfo.payeePhone){
					this.$message({
						type:'warning',
						message:'请输入收款人的手机号！'
					});
					return;
				}
				if(!tool.judge('phone',this.payInfo.payeePhone)){
					this.$message({
						type:'warning',
						message:'请输入正确的手机号！'
					});
					return;
				}
			}
			else{
				payMsg='请选择支付方式';
				if(!this.payInfo.needOrderNo){
					if(!this.payInfo.orderNo){
						this.$message({
							type:'warning',
							message:'请输入合同号'
						});
						return;
					}
				}
			}	
			if(!this.payInfo.payMode){
				this.$message({
					type:'warning',
					message:payMsg
				});
				return;
			}

			let realMoney=this.payInfo.realMoney;
			let newClassMaxMoney=this.getNewClassMaxMoney;
			let param={
				exchangePayType:this.payInfo.isRefund?2:1,
				orderSignup:{
					studentId: this.studentdetailprop.studentId,
					useEarnestMoney: this.checked ? "1" : "0",
					earnestMoney: this.payInfo.orderMoney,
					realMoney: Math.abs(realMoney),
					remark: this.payInfo.remark,
					orderNo:this.payInfo.orderNo,
					receivableMoney:Math.abs(this.payInfo.recMoney),
					classData: [
						{
							classId: this.newclass.classId,
							className: this.newclass.className,
							coursePackageId: this.newclass.coursePackageId,
							buyNum: this.buyClassTime,
							courseHour: this.buyClassTime,
							courseMoney:newClassMaxMoney,
							realMoney:Math.abs(realMoney)
						}
					],
					accountRecordData: [
						{
							payMode: this.payInfo.payMode
						}
					]
				},
				orderRefund:{
					orderRefundCourseEntityList:[
						{
							buyHour:this.oldclass.courseHour,
							chargeModeName:this.oldclass.courseTypeUnit,
							className:this.oldclass.className,
							classId: this.oldclass.classId,
							classStudentId:'',
							courseId:this.oldclass.courseId,
							courseOnePrice:this.oldclass.courseUnitPrice,
							courseTotalPrice:this.oldclass.courseMoney,
							realPayMoney:this.oldclass.realMoney,
							refundMeoey:Math.abs(this.payInfo.recMoney),
							studentCourseId:this.oldclass.studentCourseId,
							surplusClassHour:this.oldclass.courseHour-this.oldclass.courseUseHour,
							surplusMoney:this.surplusCourseMoney,
							useClassHour:this.oldclass.courseUseHour,
							useMoney:this.oldclass.courseUseHour*(this.oldclass.realMoney/(this.oldclass.courseHour||1))
						}
					],
					payMode:this.oldclass.payMode,
					payeeName:this.payInfo.payeeName,
					payeeTel:this.payInfo.payeePhone,
					refundMode:this.payInfo.payMode,
					relMoney:this.payInfo.realRefundMoney,
					remark:this.payInfo.refundReason,
					studentId:this.studentdetailprop.studentId
				},
				_wait:'',
			};
			if(this.payInfo.isRefund){
				//退费时，orderSignup为新班的钱
				param.orderSignup={
					studentId: this.studentdetailprop.studentId,
					useEarnestMoney: this.checked ? "1" : "0",
					earnestMoney: this.payInfo.orderMoney,
					realMoney: 0,//this.newclass.courseUnitPriceNumber*this.buyClassTime,
					remark: this.payInfo.remark,
					orderNo:this.payInfo.orderNo,
					receivableMoney:Math.abs(this.payInfo.recMoney),
					classData: [
						{
							classId: this.newclass.classId,
							className: this.newclass.className,
							coursePackageId: this.newclass.coursePackageId,
							buyNum: this.buyClassTime,
							courseHour: this.buyClassTime,
							courseMoney:newClassMaxMoney,
							realMoney:0,//this.newclass.courseUnitPriceNumber*this.buyClassTime
						}
					],
					accountRecordData: [
						{
							payMode: this.payInfo.payMode
						}
					]
				}
			}
			
			api.changeClass(param).then(function(data) {
				vm.successdig_payState='';
				vm.successdig_payModeName=vm.payInfo.payMode;
				if(data.resultCode===2000){
					vm.successdig_payState='审核中';
					vm.otherInfo.suceessRemark=vm.payInfo.remark+'';
					//在线支付，调起扫码支付
					if(vm.payInfo.payMode==3||vm.payInfo.payMode==4){
						// debugger
						vm.$store.dispatch("changeClass/hidechangeClassPanel");
						vm.initPayInfo([{type:'班级',className:vm.newclass.className,courseMoney:realMoney}],{
							orderSigupId:data.info.orderSignup.orderSigupId,
							realMoney:realMoney,
							payName:vm.payInfo.payMode==3?'wxpay':'alipay'
						});
						vm.initDialog();
					}
					else if(vm.payInfo.payMode==100){
						vm.successdig_payState='退费成功';
						vm.changeClassSuceess();
					}
					else{
						vm.payInfo.payModeName=tool.getDictNameByValue(vm.payInfo.payMode,'pay_mode');
						vm.successdig = true;
						vm.$store.dispatch("changeClass/hidechangeClassPanel");
						vm.initDialog();
						vm.changeClassSuceess();
					}
					
					//获取返回字段
					if(data.info&&data.info.orderSignup){
						vm.otherInfo.executeUserName=data.info.orderSignup.executeUserName;//跟单人
					}
					else if(data.info&&data.info.orderRefund){
						vm.otherInfo.orderNo=data.info.orderRefund.orderRefundId;//订单号
						vm.otherInfo.onlineOrderNo=data.info.orderRefund.payOrderNo;//第三方订单号
						vm.otherInfo.executeUserName=data.info.orderRefund.executeUserName;//跟单人
					}
				}
				else{
					vm.$message({
						type:'warning',
						message:d.message||'操作失败'
					});
				}
				
			});
		}
	},
	/**初始化二维码支付 */
	initPayInfo(countList,info){
		let goods_name = "";
		let goods_money = "";
		let payTitle = "";
		//从选择的班级、课程、商品中获取信息
		countList.forEach(item => {
			if (item.type == "班级") {
				payTitle += payTitle == '' ? item.className : '、' + item.className;
				goods_name += goods_name == "" ? item.className : "," + item.className;
				goods_money += goods_money == "" ? item.courseMoney : "," + item.courseMoney;
			} else if (item.type == "课程") {
				payTitle += payTitle == '' ? item.name : '、' + item.name;
				goods_name += goods_name == "" ? item.name : "," + item.name;
				goods_money += goods_money == "" ? item.realMoney : "," + item.realMoney;
			}
		});
		let detail = {
			goods_name: goods_name,
			goods_num: goods_money,
			body: window.config.projectName + "- 支付"
		};
		//支付参数
		let payInfo ={
			orderParas:{
				outTradeNo: info.orderSigupId, //商户订单号
				totalFee: fNumber.multiply(info.realMoney , 100),//支付金额(分)
				body: window.config.projectName + "- 支付", //显示在支付界面的标题
				tradeType: "NATIVE",//固定字段
				detail: JSON.stringify(detail),//订单详情
				campusId: this.$store.state.campusId//当前下单的校区ID
			},
			payTitle:payTitle,//支付标题
			payName:info.payName//支付方式名称
		}
		vm.$refs.payQRCode.init(payInfo);
	},
	/**支付成功 */
	suceessPay(){
		
		this.successdig = true;
		this.$store.dispatch("changeClass/hidechangeClassPanel");
		this.initDialog();
		this.payInfo.payModeName=tool.getDictNameByValue(vm.payInfo.payMode,'pay_mode');
		vm.successdig_payState='支付成功';
		vm.changeClassSuceess();
	},
	/**取消支付 */
	cancelPay(){

	},
    /**
     * 增加课程数
     */
    add() {
      if (this.buyClassTime >= this.buyMaxCourseHour) return;
	  this.buyClassTime++;
      this.getCourseTotalMoney();
    },
    /**
     * 减少课程数
     */
    reduce() {
      if (this.buyClassTime <= 1) return;
      this.buyClassTime--;
      this.getCourseTotalMoney();
	},
	alterBuyNumber(val){
		this.getCourseTotalMoney();
	},
    /**
     * 转班面板取消
     */
    handleClose() {
      // console.log(this.studentdetailprop)
      this.payInfo.remark = "";
      this.initDialog();
      this.$store.dispatch("changeClass/hidechangeClassPanel");
    },
    /**
     * 转班成功面板取消
     */
    handleClose2(done) {
    //   this.$store.dispatch("classdetail/hideclassDetailPanel");
      done();
    },
    /**
     * 选择转班班级
     */
    selectClass(val) {
      if (this.allow) {
        this.allow = false;
      }
      api.getClassInfoByIdChange({ classId: val }).then(function(d) {
        // debugger
        if (d.resultCode == 2000) {
          let classInfo = d.info;
		  if (!classInfo.coursePackage){
			   classInfo.coursePackage = {};
			   vm.allow = true;
			   vm.$message({
					type: "warning",
					message: "转入班级课程包数据为空！"
				});
			}
		  if(classInfo.totalCourseHour==0){
			  vm.allow = true;
			   vm.$message({
					type: "warning",
					message: "转入班级总课时不能为0！"
				});
			//   return;
		  }
          //班级状态
          let classStatusModeName =
            tool.getDictNameByValue(
              classInfo.classStatusMode,
              "class_status_mode"
            ) || "";
          //课程类型
          let unit = "课时";
		  let unitPrice = "";
		  //   debugger
		  let unitPriceNumber;
		  let qrb=false;
          if (classInfo.coursePackage.chargeMode == 3) {
            unit = tool.getDictNameByValue(
              classInfo.coursePackage.courseTimeMode,
              "course_time_mode"
			);
			qrb=true;
			unitPriceNumber =classInfo.coursePackage.totalMoney//全日班要付全部的钱
            //   Math.ceil(
            //     (classInfo.coursePackage.totalMoney * 100) /
            //       (classInfo.totalCourseHour||1)
			//   ) / 100;
          } else {
            unitPrice =
              Math.ceil(
                (classInfo.coursePackage.totalMoney * 100) /
                  (classInfo.coursePackage.courseHour||1)
			  ) / 100;
			unitPriceNumber=unitPrice;
		  }
		  //双师课
		 if(classInfo.courseType == 4) {
			unit = "节";
		 }
          //收费模式
          let chargeModeName = tool.getDictNameByValue(
            classInfo.coursePackage.chargeMode,
            "charge_mode"
          );
          //老师
          let teacherObj = {};
          if (classInfo.teacherList && classInfo.teacherList.length > 0) {
            teacherObj = classInfo.teacherList[0];
          }
          vm.newclass = {
			  qrb:qrb,//是否为全日班
            classId: classInfo.classId,
            className: classInfo.className,
            courseName: classInfo.courseName,
            classTeachingMode: classInfo.classTeachingMode,
            startTime: classInfo.startTime,
            endTime: classInfo.endTime,
            classRoomId: classInfo.classRoomId,
            classRoomName: classInfo.classRoomName || "",
            teacherUserId: teacherObj.userId,
            teacherUserName: teacherObj.nickName,
            totalCourseHour: classInfo.totalCourseHour,
            useCourseHour: classInfo.useCourseHour,
            courseMode: classInfo.courseMode,
            campusId: classInfo.campusId,
            coursePackageId: classInfo.coursePackageId,
            classStatusModeName: classStatusModeName, //班级状态
            courseTypeUnit: unit, //类型
			courseUnitPrice: unitPrice, //单价
			courseUnitPriceNumber:unitPriceNumber,//
			chargeModeName: chargeModeName, //收费模式
			coursePackage_totalMoney:classInfo.coursePackage.totalMoney,//课程总价
          };

          vm.buyClassTime = vm.tempcoursehour;

          vm.getCourseTotalMoney();
        } else {
          vm.$message({
            type: "warning",
            message: d.message || "操作失败！"
          });
        }
      });
    },
    /**获取totalmoney */
    getCourseTotalMoney() {
      // courseTotalMoney
      //剩余费用
		//   let price = this.newclass.courseUnitPriceNumber || 0;
		//   let buyClassTime=this.buyClassTime||0;
      let needMoney = this.getNewClassMaxMoney;
		// debugger
	  this.payInfo.recMoney = fNumber.subtract(needMoney , this.surplusCourseMoney);
	  this.payInfo.isRefund=false;
	  this.payInfo.payMode=this.oldclass.payMode;
	  if(this.payInfo.recMoney<0){
		this.payInfo.isRefund=true;
		this.payInfo.payeeName=this.studentdetailprop.parentName;
		this.payInfo.payeePhone=this.studentdetailprop.phone;
		if(this.oldclass.payMode==3||this.oldclass.payMode==4){
			this.payInfo.payMode=100;
		}
	  }

	  this.payInfo.realMoney = this.payInfo.recMoney;
	  this.payInfo.realRefundMoney=Math.abs(this.payInfo.recMoney);

      this.courseTotalMoney = this.payInfo.recMoney;
    },
    /**
     * 展示新班级
     */
    showNewClass() {
      if (!this.newclassShow) {
		//获取进班班级信息
        // this.$store.dispatch("classdetail/getClassInfo", {
        //   classId: this.newclass.classId
		// }); 
		this.getClassInfo({ classId: this.newclass.classId });
      } else {
        this.newclassShow = false;
      }
	},
	/**获取新班级信息 */
	getClassInfo(paras){
    	let classInfo=null;
    	api.getClassById(paras).then(function(data){ 
    		classInfo=data.class;
    		return api.getClassStudentList(paras);
    	}).then(function(data){
    		classInfo.studentlist=data.studentList;
    		for(let i=0;i<classInfo.studentlist.length;i++){
    			classInfo.studentlist[i].age=tool.minusDate(classInfo.studentlist[i].birthday);
    		}
			vm.classInfo=classInfo;
			vm.newclassShow = true;
    	})
	},
	/**转班成功回调 */
	changeClassSuceess(){
		this.$emit('suceess');
	}
  },
  computed: {
    /**
     * 转班面板是否显示参数
     */
    ...mapState({
      isShow: state => state.changeClass.changeClassDialog,
    //   classInfo: state => state.classdetail.classInfo
    }),
    /**
     * 可转班的班级列表
     */
    ...mapGetters("changeClass", {
      classList: "getClassList",
      oldclass: "getOldClass"
	}),
	/**原班级-课耗 */
	courseUseMoney(){
		let money=fNumber.multiply(this.oldclass.courseUnitPrice,this.oldclass.courseUseHour);
		//课耗最大为实际支付金额
		money=money>this.oldclass.realMoney?this.oldclass.realMoney:money;
		return money;
	},
	/**原班级-剩余课程费用 */
    surplusCourseMoney: function() {
	  //原班剩余费用 = 课程总价 - 课耗
	//   let surplusCourseMoney = fNumber.parseNumber(this.oldclass.courseHour*this.oldclass.courseUnitPrice - this.courseUseMoney);
	  //原班剩余费用 = 实际支付金额 - 课耗
	  let surplusCourseMoney = fNumber.parseNumber(this.oldclass.realMoney - this.courseUseMoney);
	  surplusCourseMoney=surplusCourseMoney<0?0:surplusCourseMoney;
	  return surplusCourseMoney;
	},
	
    newRealMoney: function() {
      return this.payInfo.realMoney;
    },
    tempcoursehour: function() {
      let surplusCourseHour = fNumber.subtract(this.oldclass.courseHour , this.oldclass.courseUseHour); //剩余课时差
      let newsurplusCourseHour = fNumber.subtract(this.newclass.totalCourseHour , this.newclass.useCourseHour); //新班剩余课时

      let tempcoursehour = surplusCourseHour > newsurplusCourseHour
		  ? newsurplusCourseHour : surplusCourseHour;
		if(this.newclass.qrb){
			tempcoursehour=1;
		}

      return tempcoursehour;
	},
	/**购买最大课时数：取新班剩余课时 */
	buyMaxCourseHour:function(){
		let surplusCourseHour = fNumber.subtract(this.oldclass.courseHour , this.oldclass.courseUseHour); //剩余课时差
		let newsurplusCourseHour = fNumber.subtract(this.newclass.totalCourseHour , this.newclass.useCourseHour); //新班剩余课时
		return newsurplusCourseHour;
	},
	/**新班合计金额 */
	getNewClassMaxMoney(){
		// debugger
		let m=fNumber.multiply(this.newclass.courseUnitPriceNumber,this.buyClassTime);
		// m=m>this.newclass.coursePackage_totalMoney?this.newclass.coursePackage_totalMoney:m;
		m=m<0?0:m;
		return m;
	}
  },
  watch: {
    newRealMoney(val) {
      this.payInfo.realMoney = val;
    }
  },
  mounted() {
	this.account_pay_mode = tool.getDictNameByValue(-100, "pay_mode");
	this._userInfo = tool.getItem(lsKey.user, true); //得到当前用户信息
    vm = this;
  }
};
</script>

<style lang="scss">
@import "@/style/module/utils.scss";
.changeClassContainer {
  .classInfo {
    width: inherit;
    height: auto;
    padding: 0 0.3rem 0 0.3rem;
    .StudentInfo {
      height: 0.5rem;
      width: 100%;
      .info {
        min-width: 2rem;
        height: 0.5rem;
        line-height: 0.5rem;
        float: left;
      }
    }
    .OldInfo {
      width: 100%;
      height: auto;
      margin-bottom: 0.5rem;
    }

    .SelectClassInfo {
      width: 100%;
      height: auto;
      margin-bottom: 0.5rem;
      .el-input__inner {
        border-radius: 0.08rem;
        font-size: 0.16rem;
        color: #666666;
        height: 0.36rem !important;
        line-height: 0.36rem;
      }
    }
    .NewClassInfo {
      width: 100%;
      height: auto;
      .money {
        height: 0.5rem;
        line-height: 0.5rem;
      }
    }

    .PayInfo {
      width: 100%;
      height: auto;
      .el-input__inner {
        border-radius: 0.08rem;
        font-size: 0.16rem;
        color: #666666;
        height: 0.36rem !important;
        line-height: 0.36rem;
      }
      .row {
        width: 100%;
        font-size: 0.16rem;
        margin: 0.16rem 0;
      }
      .spanlabel {
        display: inline-block;
        width: 1rem;
        text-align: right;
      }
    }
  }
  /** 转班成功dialog**/
  .successDetail {
    width: inherit;
    //  max-height: 10rem;
    padding: 0 0.2rem 0.2rem 0.2rem;
    .newclassinfo {
      width: inherit;
      margin-bottom: 0.5rem;
      .classlistinfo {
        width: inherit;
        max-height: 1rem;
      }
      .proceeds {
        width: inherit;
        max-height: 1rem;
        ul {
          width: inherit;
          height: inherit;
          li {
            list-style-type: none;
            text-align: right;
          }
        }
      }
      .otherinfo {
        width: inherit;
        max-height: 1.5rem;
        /*ul{
			    		width:inherit;
			    		height: inherit;
			    		li{
			    			list-style-type: none;
			    			text-align: left;
			    		}
			    	}*/
      }
    }
    .newclassdetail {
      width: inherit;
      max-height: 7rem;
    }
    .newclassBtn {
      width: inherit;
      height: 0.2rem;
      line-height: 0.2rem;
      text-align: center;
      cursor: pointer;
      margin-bottom: 0.2rem;
    }
    .classdetailInfo {
      width: inherit;
      height: auto;
    }
  }

  /**自定义对话框标题样式**/
  .panel_title {
    padding: 0.23rem 0.31rem 0.23rem 0.31rem;
    font-size: 0.22rem;
    font-family: "microsoft yahei";
    color: #333333;
  }
  .panel_title2 {
    padding: 0.23rem 0.31rem 0.23rem 0.31rem;
    font-size: 0.22rem;
    font-family: "microsoft yahei";
    color: #333333;
    text-align: center;
  }
  /**
		 * 自定义对话框样式
		 */
  .el-dialog-bg {
    background: #ffffff;
    width: 10rem;
    border-radius: 0.1rem;
    margin-top: 10vh !important;
    .el-dialog__header {
      padding: 0px;
    }
    .el-dialog__body {
      padding: 0px !important;
    }
    .el-dialog__footer {
      padding: 0.3rem;
      .footer-btn {
        width: 100%;
        text-align: center;
      }
    }
  }
  // 必须图标
  span[necessary="true"]::before {
    content: "*";
    color: #f56c6c;
    margin-right: 4px;
  }
}
</style>
















			      					